/**
* 
*  FIFO sched
* see <a href="{@docRoot}/Documentation/scheduler.html"> for more information</a>
*  Copyright (c) 2009 Ecole Centrale de Nantes IRCCyN
* @author: Anne-Marie.Deplanche 16-01
* @version
*/
package storm.Schedulers;
import java.util.*;
import storm.*;
import storm.Processors.*;
import storm.Tasks.*;

/**
 * 
 * @author Anne-Marie.Deplanche 16-01
 *
 */
public class FIFO_Scheduler extends Scheduler {

	
	private LinkedList list_ready;
	private Boolean todo = false;
	/**
	 * 
	 */
	public void init() {
		super.init();
		list_ready = new LinkedList();
	}
	/**
	 * 
	 */
	public void onActivate(EvtContext c) {
		list_ready.addLast(c.getCible());
	}
	/**
	 * 
	 */
	public void onUnBlock(EvtContext c){
		list_ready.addLast(c.getSource());
	}
	/**
	 * 
	 */
	public void onBlock(EvtContext c){
		list_ready.remove(c.getCible());
	}
	/**
	 * 
	 */
	public void onTerminated(EvtContext c){
		list_ready.remove(c.getCible());
	}
	/**
	 * 
	 */
	public void sched(){
			select();
	}
	/**
	 * 
	 */
	public void select() {
		ArrayList CPUS =
			this.Kernel.getTasksListeManager().getProcessors();
		Iterator CPU = CPUS.iterator();
		while (CPU.hasNext()) {
			Processor p = (Processor) CPU.next();
			if (!p.isRunning()) {
				Iterator task= list_ready.iterator();
				while (task.hasNext()) {
					Task t=(Task) task.next();
					if (!t.isIsrunning()) {
							t.runningOn(p);
							break;
						}
				}
			}
		}
	}
}